Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

package db tests #23

Merged
merged 20 commits into from
May 14, 2024
Merged

Conversation

yannick2009
Copy link
Contributor

Launch go test -cover ./... to run the tests and see the percentage of coverage.

@theredditbandit theredditbandit linked an issue May 11, 2024 that may be closed by this pull request
Copy link
Contributor

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad you added tests.

I made some feedbacks about your changes

cmd/set.go Outdated
Comment on lines 24 to 30
cmd.SilenceUsage = true
return errors.New("Not implemented yet")
fmt.Println("Not implemented yet")
return ErrFlagNotImplemented
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this change

Using fmt.Println won't send message to stderr but stdout

Is the cause the fact you are using testify assert.Equal(t, ErrFlagNotImplemented, err) ?

The errors were wrapped now, they are reported unwrapped

cmd/set.go Outdated
Comment on lines 13 to 14
ErrFlagNotImplemented error = errors.New("flag not implemented yet")
ErrBadUsageSetCmd error = errors.New("bad usage of set command")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to define the type to error here

cmd/root.go Outdated
Comment on lines 10 to 13
StatusBucket string = "projects"
ProjectPathBucket string = "projectPaths"
ProjectAliasBucket string = "projectAliases"
version string = "1.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to define the type string here.

cmd/ls.go Outdated
Comment on lines 21 to 32
oldUi, _ := cmd.Flags().GetBool("o")
data, err := db.GetAllRecords(StatusBucket)
data, err := db.GetAllRecords(db.DBName, StatusBucket)
if err != nil {
return err
}
if filterFlag != "" {
fmt.Println("Filtering by status : ", filterFlag)
data = utils.FilterByStatus(data, filterFlag)
data := utils.FilterByStatus(data, filterFlag)
ui.RenderTable(data)
}
if oldUi {
return ui.RenderTable(data)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are removing everything about oldui, I don't understand.

It might be legitimate but I don't get it

cmd/reset.go Outdated Show resolved Hide resolved
})

t.Run("Test WriteToDB with empty bucketname", func(t *testing.T) {
dbname := db.DBTestName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are defining it in almost every single test. Add a const at the beginning of _test package and stop redefining again and again

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are talking about what in this part ? i don't get it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding a const dbname := db.DBTestName at the top of the package

so you don't have to repeat it everywhere. And when you need to set it to empty string, as I think it's the only other use case, you can then use either another variable or using dbname := ""

Comment on lines 171 to 172
require.Error(t, err)
require.ErrorIs(t, err, db.ErrWriteToDB)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ErrorIs implies Error

So no need to use Error here


require.Error(t, err)
require.ErrorIs(t, err, expectedErr)
require.Equal(t, records, expectedValue)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equal(t, expected, actual)

You inverted

Comment on lines 432 to 433
require.Error(t, err)
require.Equal(t, expectedErr, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use

require.ErrorIs(t, err, expectedErr)

pkg/indexer.go Outdated
Comment on lines 44 to 45
fmt.Println(err)
return ErrIndexDir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No fmt.Println should be called.

Using this would be better

return fmt.Errorf("%w: %w")

Or simply a join

@ccoVeille
Copy link
Contributor

I would ask you to wait before #27 to be merged if you are OK guys

it would report CI errors on your code

@theredditbandit theredditbandit requested a review from ccoVeille May 12, 2024 04:41
@ccoVeille
Copy link
Contributor

ccoVeille commented May 12, 2024

@theredditbandit you asked me to review, but I will wait for the CI changes to be rebased in this branch, so we could see what the CI will report

@ccoVeille
Copy link
Contributor

I will need to be in front of a computer to review in details, but I'm impressed by the changes you made @yannick2009

@theredditbandit
Copy link
Owner

@ccoVeille can you figure out why ci is breaking , I can't make sense of the error message.

@theredditbandit
Copy link
Owner

Finally all checks pass! 🎉

To get rid of the error I had to run

gci write -s standard -s default -s 'prefix(github.com/theredditbandit/pman)' .

to format it like golangci-lint likes it

@ccoVeille did you have any thoughts on these changes

Copy link
Owner

@theredditbandit theredditbandit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏽

@theredditbandit theredditbandit merged commit 84d937a into theredditbandit:master May 14, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lack of tests
3 participants